package com.flower8.service.impl;

import com.flower8.dao.MessageDao;
import com.flower8.dao.PointDao;
import com.flower8.model.PointMall;
import com.flower8.service.PointService;
import com.flower8.sysconfig.constants.SysConstants;
import com.flower8.utils.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: tanglin
 * @Date: 2019/12/31 17:47
 * @Version: 1.0
 */
@Service
public class PointServiceImpl implements PointService {

    @Autowired
    private PointDao pointDao;

    @Autowired
    private MessageDao messageDao;

    /**
     * 查询积分商城商品列表
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public List<Map> getPointMallList(PageData pd) throws Exception {
        return pointDao.getPointMallList(pd);
    }

    /**
     * 查询积分商城商品列表
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public int getPointMallCount(PageData pd) throws Exception {
        return pointDao.getPointMallCount(pd);
    }

    /**
     * 根据积分商品ID查询
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public Map getPointMallById(long id) throws Exception {
        return pointDao.getPointMallById(id);
    }

    /**
     * 更新积分商城商品
     * @param pointMall
     * @throws Exception
     */
    @Override
    @Transactional
    public void updatePointMall(PointMall pointMall) throws Exception {
        pointDao.updatePointMall(pointMall);
    }

    /**
     * 新增积分商城商品
     * @param pointMall
     * @throws Exception
     */
    @Override
    @Transactional
    public void addPointMall(PointMall pointMall) throws Exception {
        pointDao.addPointMall(pointMall);
    }

    /**
     * 删除积分商城商品
     * @param id
     * @throws Exception
     */
    @Override
    public void deletePointMall(long id) throws Exception {
        pointDao.deletePointMall(id);
    }

    /**
     * 积分商城兑换记录
     * @param param
     * @throws Exception
     */
    @Override
    public List<Map> getMallRecordList(Map param) throws Exception {
        return pointDao.getMallRecordList(param);
    }

    /**
     * 积分商城兑换记录数量
     * @param param
     * @return
     * @throws Exception
     */
    @Override
    public int getMallRecordListCount(Map param) throws Exception {
        return pointDao.getMallRecordListCount(param);
    }

    /**
     * 发放兑换商品
     * @param param
     * @throws Exception
     */
    @Override
    @Transactional
    public void sendMallRecord(Map param) throws Exception {
        pointDao.sendMallRecord(param);
        //发送一条消息
        Map msgParam = new HashMap();
        msgParam.put("uid", param.get("uid").toString());
        msgParam.put("type", 1);
        msgParam.put("category", 2);
        msgParam.put("contents", param.get("content").toString());
        msgParam.put("icon", SysConstants.MSG1);
        messageDao.addMsg(msgParam);
    }
}
